using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Blogs.LazyFox.Models
{
    [Table("Blogs")]
    public class BlogModel
    {
        [Key]
        public long Bid { get; set; }
        [MaxLength(100)]
        public string Title { get; set; } = "NoTitle";
        [MaxLength(100)]
        public string cover { get; set; } = string.Empty;
        [MaxLength(300)]
        public string Introduction { get; set; } = string.Empty;
        public DateTime CreateTime { get; set; }
        public string Article { get; set; } = string.Empty;
        public string AuthorId { get; set; } = string.Empty;
        public PersonModel Author { get; set; } = null!;
        public List<TagModel> Tags { get; set; } = null!;

        public bool hasTag(string[] searchTags)
        {
            foreach (var tag in Tags)
            {
                if (Array.IndexOf(searchTags, tag.Name) > -1) return true;
            }
            return false;
        }
    }
}